﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace LeetCodeSolutions
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("题目序号：");
            string idStr = Console.ReadLine();

            try
            {
                string className = string.Format("LeetCodeSolutions.LeetCode{0}", idStr);
                Type type = Type.GetType(className);
                if (type == null)
                {
                    CommonFuntions.Print("题目不存在");
                    return;
                }
                object instance = Activator.CreateInstance(type);
                if (!(instance is LeetCodeBase))
                {
                    CommonFuntions.Print("用例类型错误：", instance.GetType().ToString());
                    return;
                }
                CommonFuntions.Print("执行", className, ":\n");
                LeetCodeBase unit = instance as LeetCodeBase;

                Stopwatch sw = new Stopwatch();
                sw.Start();
                unit.Execute();
                sw.Stop();
                CommonFuntions.Print("执行耗时：", sw.Elapsed.TotalSeconds.ToString(), "s");
            }
            catch (Exception e)
            {
                CommonFuntions.Print(e);
            }

            Console.ReadKey();
        }
    }
}
